package smecta.client.print.service;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import smecta.client.print.domain.ScpPackage;
import smecta.client.print.mapper.ScpPackageMapper;
import tk.mybatis.mapper.entity.Example;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class ScpProduceService extends BaseService<ScpPackage> {

    @Autowired
    private ScpPackageMapper scpPackageMapper;

    public List<String> getAllBatchNumList(){
        List<ScpPackage> allList = scpPackageMapper.selectAll();
        return allList.stream().map(ScpPackage::getPihao).collect(Collectors.toList());
    }

    public List<ScpPackage> getListByBatchNum(String batchNum){
        if (StringUtils.isBlank(batchNum)){
            return new ArrayList<>();
        }
        Example example = new Example(ScpPackage.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("pihao", batchNum);
        criteria.andEqualTo("tingyong", "否");
        return selectByExample(example);
    }

    public ScpPackage findById(Long produceId) {
        ScpPackage scpPackage = new ScpPackage();
        if (produceId == null){
            return scpPackage;
        }
        scpPackage.setProductId(produceId);
        return selectOne(scpPackage);
    }
}
